﻿using EntityFrameworks.Web.Core.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;


namespace apiApplication1.Controllers
{
    [CorsAttribute("http://localhost:11879/", "http://localhost:5008/")]/*需要加在类上/，呵呵。*/
    [AllowAnonymous]
    public class ValuesController : ApiController
    {
        [AllowAnonymous]
        /// <summary>
        /// 只对下面的URI进行约定，它们可以跨域访问，对外不提供jsonp
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Contact> Get()
        {
            Contact[] contacts = new Contact[]
            {
                new Contact{Id=1, Name="张三", PhoneNo="123", EmailAddress="zhangsan@gmail.com"},
                new Contact{Id=2, Name="李四", PhoneNo="456", EmailAddress="lisi@gmail.com"},
                new Contact{Id=3, Name="王五", PhoneNo="789", EmailAddress="wangwu@gmail.com"},
            };
            return contacts;
        }
        public Contact Get(string name)
        {
            return new Contact { Id = 2, Name = "李四", PhoneNo = "456", EmailAddress = "lisi@gmail.com" };
        }
        public Contact Get(int id)
        {
            return new Contact { Name = "张三", PhoneNo = "123", EmailAddress = "zhangsan@gmail.com" };
        }
        // POST api/values
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        [BasicAuthenticationAttribute]
        // DELETE api/values/5
        public HttpResponseMessage Delete(int id)
        {
            return new HttpResponseMessage(HttpStatusCode.NoContent);
        }

    }

    public class Contact
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string PhoneNo { get; set; }
        public string EmailAddress { get; set; }
    }
}